﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ArriviSoft.SlotMachine.Model.Tests
{
    [TestClass]
    public class MachineTests
    {
        [TestMethod]
        public void DefaultIsZeroCoinsLeft()
        {
            ISlotGenerator mockGenerator = new MockGenerator(2, new int[] { 0, 0, 0, 0 });
            ISlotValidator mockValidator = new MockValidator(5);

            SlotMachine machine = new SlotMachine(mockGenerator, mockValidator);


            Assert.AreEqual(0, machine.Coins);
        }

        [TestMethod]
        public void InsertCoin()
        {
            ISlotGenerator mockGenerator = new MockGenerator(2, new int[] { 0, 0, 0, 0 });
            ISlotValidator mockValidator = new MockValidator(5);

            SlotMachine machine = new SlotMachine(mockGenerator, mockValidator);


            machine.InsertCoins(1);

            Assert.AreEqual(1, machine.Coins);

        }

        [TestMethod]
        public void InsertFiveCoins()
        {
            ISlotGenerator mockGenerator = new MockGenerator(2, new int[] { 0, 0, 0, 0 });
            ISlotValidator mockValidator = new MockValidator(5);

            SlotMachine machine = new SlotMachine(mockGenerator, mockValidator);


            machine.InsertCoins(5);

            Assert.AreEqual(5, machine.Coins);
        }

        [Ignore]
        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void UnableToPlayWithoutCoins()
        {
            ISlotGenerator mockGenerator = new MockGenerator(2, new int[] { 0, 0, 0, 0 });
            ISlotValidator mockValidator = new MockValidator(5);

            SlotMachine machine = new SlotMachine(mockGenerator, mockValidator);


            // machine.InsertCoins(1);

            machine.Play();
        }

        [TestMethod]
        public void PlayWithoutPrize()
        {
            ISlotGenerator mockGenerator = new MockGenerator(2, new int[] { 0, 0, 0, 0 });
            ISlotValidator mockValidator = new MockValidator(0);

            SlotMachine machine = new SlotMachine(mockGenerator, mockValidator);


            machine.InsertCoins(1);

            Outcome result = machine.Play();

            Assert.AreEqual(0, result.Prize);
            Assert.AreEqual(0, machine.Coins);
        }

        [TestMethod]
        public void PlayAndGetFourZeros()
        {
            ISlotGenerator mockGenerator = new MockGenerator(2, new int[] { 0, 0, 0, 0 });
            ISlotValidator mockValidator = new MockValidator(5);

            SlotMachine machine = new SlotMachine(mockGenerator, mockValidator);

            machine.InsertCoins(1);

            Outcome result = machine.Play();

            Assert.AreEqual(5, result.Prize);
            Assert.AreEqual(0, machine.Coins);
        }

        [TestMethod]
        public void PlayAndGetFourTimesOne()
        {
            ISlotGenerator mockGenerator = new MockGenerator(2, new int[] { 1,1,1,1 });
            ISlotValidator mockValidator = new SlotValidator();

            SlotMachine machine = new SlotMachine(mockGenerator, mockValidator);

            machine.InsertCoins(1);

            Outcome result = machine.Play();

            Assert.AreEqual(8, result.Prize);
            Assert.AreEqual(0, machine.Coins);
        }

        [TestMethod]
        public void PlayAndGetFourTimesTwo()
        {
            ISlotGenerator mockGenerator = new MockGenerator(3, new int[] { 2,2,2,2 });
            ISlotValidator mockValidator = new SlotValidator();

            SlotMachine machine = new SlotMachine(mockGenerator, mockValidator);

            machine.InsertCoins(1);

            Outcome result = machine.Play();

            Assert.AreEqual(12, result.Prize);
            Assert.AreEqual(0, machine.Coins);
        }
    }
}
